<?php
namespace zake\foundation\reactor\trigger\connect;


use zake\helper\Console;

class WsConnect extends BeeConnect
{


    // 事件类型
    const EVENT_HAND_SHARK = '_connect_event_handShark';


    /**
     * 握手状态
     * @var bool
     */
    private $webSocketHandshake = false;


    /**
     * 协议打包方式
     * @var int
     */
    public $webSocketType = 0;


    /**
     * 协议帧数组缓冲区
     * @var array
     */
    private $frame = [];


    /**
     * 协议握手协议帧
     * @var string
     */
    private $sharkFrame = "";


    /**
     * 构造器
     * WsConnect constructor.
     * @param $resource
     */
    public function __construct($resource)
    {
        parent::__construct($resource);
    }


    /**
     * 是否握手
     *
     * @author liu.bin 2020-04-22 15:13
     */
    public function isHandShake()
    {
        return $this->webSocketHandshake;
    }

    /**
     * 握手成功
     *
     * @author liu.bin 2020-04-23 16:18
     */
    public function handShakeSuccessful()
    {
        $this->webSocketHandshake = true;
    }


    /**
     * 定义
     * @param String $sharkFrame
     *
     * @author liu.bin 2020-09-03 11:36
     */
    public function setSharkFrame(String $sharkFrame){
        $this->sharkFrame = $sharkFrame;
    }


    /**
     * 获取
     * @return string
     *
     * @author liu.bin 2020-09-03 11:36
     */
    public function getSharkFrame(){
        return $this->sharkFrame;
    }



    /**
     * 追加协议帧
     * 如果当前帧非最后一帧，需要缓冲到内存，后期统一处理
     *
     * @author liu.bin 2020-09-02 15:46
     */
    public function pushFrame($frameBuffer){
        array_push($this->frame,$frameBuffer);
    }


    /**
     * 获取当前协议帧
     * @return array
     *
     * @author liu.bin 2020-09-02 15:51
     */
    public function frameList(){
        return $this->frame;
    }



    public function __destruct()
    {
        Console::success("ws connect stream __destruct");
    }

}
